package pattern.creational.singleton;

/**
 * 单例模式，双重检查加上禁止指令重排序
 *
 * @Author Gavin
 * @date 2020.07.15 12:07
 */
public class LazyDoubleCheckSingleton {
    public volatile static LazyDoubleCheckSingleton instance = null;

    private LazyDoubleCheckSingleton() {
    }

    public static LazyDoubleCheckSingleton getInstance() {
        if (instance == null) {
            synchronized (LazyDoubleCheckSingleton.class) {
                if (instance == null) {
                    instance = new LazyDoubleCheckSingleton();
                }
            }
        }
        return instance;
    }
}
